<template>
	<div class="role" v-if="dialogFormVisible">
		<el-dialog :title="title" :visible="dialogFormVisible" width="800px" :close-on-click-modal="false" :before-close="handleClose">
			<div class="tab">
				<el-form ref="form" :rules="rules" :model="form" label-width="100px">
					<el-row>
						<el-col :span="12">
							<el-form-item label="设备名称:" prop="name">
								{{form.name}}
							</el-form-item>
							<el-form-item label="设备型号:" prop="model">
								{{form.model}}
							</el-form-item>
							<el-form-item label="设备类型:" prop="type">
								{{form.type}}
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="位置:" prop="localtion">
								{{form.localtion}}
							</el-form-item>
							<el-form-item label="品牌:">
								{{form.manufactor}}
							</el-form-item>
							<el-form-item label="购入时间:">
								{{form.buy_time}}
							</el-form-item>
						</el-col>
					</el-row>
					<el-form-item label="接收人">
						<el-select
							v-model="form.receive_user"
							placeholder="请选择"
							style="width:100%;">
							<el-option
								v-for="item in options"
								:key="item.id"
								:label="item.name"
								:value="item.id">
							</el-option>
						</el-select>
					</el-form-item>
				</el-form>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button @click="handleClose">取 消</el-button>
				<el-button type="primary" @click="add('form')">提 交</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
import { getHeader } from '@/app.config'
import {userList,deviceTransfer} from '@/api/user'

export default {
	name: 'addForm',
	data(){
		return {
			headers:{'Content-Type':'multipart/form-data'},
			dialogFormVisible:false,
			form:{
				name:''
			},
			id:'',
			rules:{

			},
			options:[],
			num:0,
			title:'借出',
			fileList:[]
		}
	},
	created() {

	},
	methods:{
		handleClose(){
			this.dialogFormVisible = false
			this.form = {}
		},
		add(form){
			this.$refs[form].validate((valid) => {
				if (valid) {
					var data = {
						'receive_user':this.form.receive_user
					}
					deviceTransfer(data,this.id).then(res => {
						this.dialogFormVisible = false
						this.form = {}
						this.$parent.initTable()
						this.$message.success(res.message)
					})
					// var source = `${process.env.VUE_APP_KANBAN_HOST}/api/v1/prototype/${this.id}/transfer`;

					// this.$axios.post(source,data,{headers: getHeader()})
					// 	.then((response) => {
					// 		if (response.status == 200) {
					// 			this.dialogFormVisible = false
					// 			this.form = {}
					// 			this.$parent.initTable()
					// 			this.$message.success(response.data.message)
					// 		}
					// 	}).catch((err) => {
					// 	console.log(err);
					// });
				} else {
					this.$message.error(res.message)
					this.dialogFormVisible = false
					this.form = {}
				}
			});

		},
		getTime(data){
			var d = new Date(data);
			var d2 = d.getTime() - 8 * 60 * 60 * 1000
			d = new Date(d2)
			var  resDate = d.getFullYear() + '-' +
				((d.getMonth() + 1)<10?'0'+(d.getMonth() + 1):(d.getMonth() + 1)) + '-' +
				(d.getDate()<10?'0'+d.getDate():d.getDate())+ ' '+
				(d.getHours()<10?'0'+d.getHours():d.getHours())+':'+
				(d.getMinutes()<10?'0'+d.getMinutes():d.getMinutes())+':'+
				(d.getSeconds()<10?'0'+d.getSeconds():d.getSeconds());
			return resDate
		},
		initData(num,data){
			this.num = num
			this.id = data.id
			this.form = Object.assign({},data)
			this.form.buy_time = this.getTime(this.form.buy_time)
			userList().then(res => {
				this.options = res.data
			})
		}
	}

}
</script>

<style lang="scss" scoped>
.role{
	//.tab{
	//	width: 450px;
	//	margin: 0 0 0 40px;
	//}
}
</style>
